package com.sanyang.lawyer.controller.finance;

import com.sanyang.lawyer.entity.Finance_invoice;
import com.sanyang.lawyer.entity.Finance_invoice_type;
import com.sanyang.lawyer.entity.Finance_open_project;
import com.sanyang.lawyer.service.finance.Finance_invoiceService;
import com.sanyang.lawyer.service.finance.Finance_invoice_typeService;
import com.sanyang.lawyer.service.finance.Finance_open_projectService;
import com.sanyang.lawyer.utils.FastDFSutils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartRequest;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: lawyer
 * @description: 发票
 * @author: lql
 * @create: 2019-10-16 19:30
 **/
@RestController
@RequestMapping("financeInvoiceController")
public class FinanceInvoiceController {

        @Autowired
        private Finance_invoice_typeService finance_invoice_typeService;
        //开具项目表
        @Autowired
        private Finance_open_projectService finance_open_projectService;
        //发票
        @Autowired
        private Finance_invoiceService finance_invoiceService;
        //文件上传
        @Autowired
        private FastDFSutils fastDFSutils;


        @RequestMapping("invoicetypelist")
        @ResponseBody
        public List<Finance_invoice_type> invoicetypelist(){
            List<Finance_invoice_type> list=finance_invoice_typeService.list();
            return list;
        }

        //开具项目类型
        @RequestMapping("openproject")
        @ResponseBody
        public List<Finance_open_project> openproject(){
            List<Finance_open_project> list=finance_open_projectService.list();
            return list;
        }

        //发票遍历
        @RequestMapping("invoicelist")
        @ResponseBody
        public List<Finance_invoice> invoicelist(String opentype,int invoicetype,int openproject,int caseid,String inputdate,String enteringdate,String caselawid,String cookie){
            Map<String,String> map=mapsel(opentype,invoicetype,openproject,caseid,inputdate,enteringdate,caselawid,cookie);
            List<Finance_invoice> list=finance_invoiceService.list(map);
            return list;
        }

        public Map<String,String> mapsel(String opentype,int invoicetype,int openproject,int caseid,String inputdate,String enteringdate,String caselawid,String cookie){
            Map<String,String> map=new HashMap<String,String>();
            map.put("opentype",opentype);
            map.put("invoicetype",Integer.toString(invoicetype));
            map.put("openproject",Integer.toString(openproject));
            map.put("caseid",Integer.toString(caseid));
            map.put("inputdate",inputdate);
            map.put("enteringdate",enteringdate);
            map.put("caselawid",caselawid);
            map.put("cookie",cookie);
            return map;
        }

        //修改发票状态
        @RequestMapping("update")
        @ResponseBody
        public int update(Finance_invoice finance_invoice){
            return finance_invoiceService.update(finance_invoice);
        }

        //根据caseid查找
        @RequestMapping("getByCase")
        @ResponseBody
        public List<Finance_invoice> getByCase(String caseId){
            List<Finance_invoice> list=finance_invoiceService.getByCase(caseId);
            return list;
        }

        //添加
        @RequestMapping("add")
        @ResponseBody
        public int add(String file,String caseid, String invoiceTitle, String invoiceMoney, String projectId, String openType, String invoiceTypeId, String taxPayerIdemtity, String invoiceNumber, String invoiceDate, String taxId, String basicBank, String accountNumber, String registerdAddress, String fixedlineTelephone, String applicationRemark, String invoiceRemark){
            Map<String,String> map=mapadd(file,caseid,  invoiceTitle,  invoiceMoney,  projectId,  openType,  invoiceTypeId,  taxPayerIdemtity,  invoiceNumber,  invoiceDate,  taxId,  basicBank,  accountNumber,  registerdAddress,  fixedlineTelephone,  applicationRemark,  invoiceRemark);
            int i=finance_invoiceService.add(map);
            return i;
        }

        public Map<String,String> mapadd(String  file, String caseid, String invoiceTitle, String invoiceMoney, String projectId, String openType, String invoiceTypeId, String taxPayerIdemtity, String invoiceNumber, String invoiceDate, String taxId, String basicBank, String accountNumber, String registerdAddress, String fixedlineTelephone, String applicationRemark, String invoiceRemark){
            Map<String,String> map=new HashMap<String,String>();
            map.put("invoiceTitle",invoiceTitle);map.put("invoiceMoney",invoiceMoney);
            map.put("projectId",projectId);map.put("openType",openType);
            map.put("invoiceTypeId",invoiceTypeId);map.put("taxPayerIdemtity",taxPayerIdemtity);
            map.put("invoiceNumber",invoiceNumber);map.put("invoiceDate",invoiceDate);
            map.put("caseid",caseid);
            map.put("basicBank",basicBank);
            map.put("accountNumber",accountNumber);
            map.put("registerdAddress",registerdAddress);
            map.put("fixedlineTelephone",fixedlineTelephone);
            map.put("applicationRemark",applicationRemark);
            map.put("invoiceRemark",invoiceRemark);
            System.out.println(file);
            map.put("",file);
            return map;
        }

        //删除
        @RequestMapping("del")
        @ResponseBody
        public int del(int invoiceId){
            int i=finance_invoiceService.del(invoiceId);
            return i;
        }

        //根据id查询
        @RequestMapping("getById")
        @ResponseBody
        public Finance_invoice getbyid(int invoiceId){
            Finance_invoice finance_invoice=finance_invoiceService.getById(invoiceId);
            return finance_invoice;
        }
}


